package practice.library.gremlin_scala.trial.tour.api

import com.thinkaurelius.titan.core.TitanGraph
import com.thinkaurelius.titan.graphdb.database.StandardTitanGraph
import com.thinkaurelius.titan.graphdb.vertices.CacheVertex

/**
  * Created by lovepocky on 16/7/6.
  */
object example {

	import practice.library.gremlin_scala.example.ConsoleExample
	import gremlin.scala._
	import practice.library.gremlin_scala.trial.tour.model._

	import scala.collection.JavaConverters._
	import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet
	import org.apache.tinkerpop.gremlin.structure.T

	def main(args: Array[String]) {
		val g = ConsoleExample.graphOfCassandraWith160()

		getVertexGroupedByLabelWithSpecificLabelEdge_example(g.V.hasLabel("city").head(), "location", 4)
			.foreach(it => println((it._1, it._2.foldLeft("\n")((a, b) => a + b.valueMap + "\n"))))

		getVertexTransformed2CC(g)
			.foreach(println)

		g.close()
	}

	def getVertexTransformed2CC(g: ScalaGraph[TitanGraph]): List[_] = {
		g.V.map(vertex.transform2CC).toList()
	}

	def getVertexGroupedByLabelWithSpecificLabelEdge_example(vertex: Vertex, specificLabelEdge: String, limit: Int): scala.collection.Map[String, List[Vertex]] = {
		vertex.both(specificLabelEdge).group().by(T.label).head()
			.asInstanceOf[java.util.Map[String, BulkSet[Vertex]]].asScala
			.mapValues(_.asScala.toList.take(limit))
	}
}
